package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.AdminDaliyTask;
import com.ruoyi.system.service.IAdminDaliyTaskService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 日报任务Controller
 * 
 * @author ruoyi
 * @date 2021-01-06
 */
@Controller
@RequestMapping("/system/task")
public class AdminDaliyTaskController extends BaseController
{
    private String prefix = "system/task";

    @Autowired
    private IAdminDaliyTaskService adminDaliyTaskService;

    @RequiresPermissions("system:task:view")
    @GetMapping()
    public String task()
    {
        return prefix + "/task";
    }

    /**
     * 查询日报任务列表
     */
    @RequiresPermissions("system:task:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AdminDaliyTask adminDaliyTask)
    {
        startPage();
        List<AdminDaliyTask> list = adminDaliyTaskService.selectAdminDaliyTaskList(adminDaliyTask);
        return getDataTable(list);
    }

    /**
     * 导出日报任务列表
     */
    @RequiresPermissions("system:task:export")
    @Log(title = "日报任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AdminDaliyTask adminDaliyTask)
    {
        List<AdminDaliyTask> list = adminDaliyTaskService.selectAdminDaliyTaskList(adminDaliyTask);
        ExcelUtil<AdminDaliyTask> util = new ExcelUtil<AdminDaliyTask>(AdminDaliyTask.class);
        return util.exportExcel(list, "task");
    }

    /**
     * 新增日报任务
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存日报任务
     */
    @RequiresPermissions("system:task:add")
    @Log(title = "日报任务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AdminDaliyTask adminDaliyTask)
    {
        return toAjax(adminDaliyTaskService.insertAdminDaliyTask(adminDaliyTask));
    }

    /**
     * 修改日报任务
     */
    @GetMapping("/edit/{taskId}")
    public String edit(@PathVariable("taskId") Long taskId, ModelMap mmap)
    {
        AdminDaliyTask adminDaliyTask = adminDaliyTaskService.selectAdminDaliyTaskById(taskId);
        mmap.put("adminDaliyTask", adminDaliyTask);
        return prefix + "/edit";
    }

    /**
     * 修改保存日报任务
     */
    @RequiresPermissions("system:task:edit")
    @Log(title = "日报任务", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AdminDaliyTask adminDaliyTask)
    {
        return toAjax(adminDaliyTaskService.updateAdminDaliyTask(adminDaliyTask));
    }

    /**
     * 删除日报任务
     */
    @RequiresPermissions("system:task:remove")
    @Log(title = "日报任务", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(adminDaliyTaskService.deleteAdminDaliyTaskByIds(ids));
    }
}
